/**
 * 系统后台授权管理配置配置JS-systemDataSource.jsp
 */

// 项目路径
var strPath = window.document.location.pathname;
//var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
var postPath = "/gdp";

$(function () {
    getSNNumber();
    var sign = $("#asd").val();
    if (sign == 1) {
        bootbox.alert("您的授权文件已过期，请重新上传授权文件！");
    }
//	$("#file_submit").click(function(){
//		console.info($("#file-0a").val())
//		if($("#file-0a").val()==""){
//			return ;
//		}
//		$.ajaxFileUpload({
//			url : postPath + '/system/authorization/uploadSyfBase',
//			type : 'post',
//			secureuri : false,
//			fileElementId : 'file-0a',
//			dataType : 'json',
//			data : "",
//			success : function(data, status) {
//				if (data) {
//					bootbox.alert("保存成功!");
//				} else {
//					bootbox.alert("保存失败,请刷新后重试!");
//				}
//				//$('#fileToUpload').replaceWith('<input id="fileToUpload" type="file" name="file" />');
//			},
//			error : function(data, status, e) {
//				bootbox.alert("上传发生异常!");
//				//alert("上传发生异常");
//			}
//		});
//	});
})
$('#file-0a').fileinput({
    language: 'zh', //设置语言
    uploadUrl: 'system/authorization/uploadSyfBase', //上传的地址
    //allowedFileExtensions: ['java', 'txt', 'dll'],//接收的文件后缀
    //uploadExtraData:{"id": 1, "fileName":'123.mp3'},
    autoReplace: true,
    maxFileCount: 1,
    browseClass: "btn btn-primary", //按钮样式
    previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
    uploadAsync: true, //默认异步上传
    showUpload: true, //是否显示上传按钮
    showRemove: true, //显示移除按钮
    showPreview: true, //是否显示预览
    browseClass: "btn blue-steel",
    allowedFileExtensions: ['dll'],

});
$('#file-0a').on('filepreupload', function (event, data, previewId, index) {     //上传中
    var form = data.form, files = data.files, extra = data.extra,
        response = data.response, reader = data.reader;
    //console.log('文件正在上传');
    return;
})
$('#file-0a').on("fileuploaded", function (event, data, previewId, index) {    //一个文件上传成功
    //console.log('文件上传成功！'+data.jqXHR.responseJSON.msg);
    if (!data.jqXHR.responseJSON.success) {
        bootbox.alert(data.jqXHR.responseJSON.msg);
    }
})
$('#file-0a').on('fileerror', function (event, data, msg) {  //一个文件上传失败
    //console.log('文件上传失败！'+data.id);
    bootbox.alert(data.jqXHR.responseJSON.msg);
})

$("#btn_validate").click(function () {
    //console.info($("#file-0a").val())
    $.ajax({
        type: "POST",
        url: postPath + '/system/authorization/validationSyfBase',
        data: "",
        dataType: 'json',
        async: false,
        //contentType:'application/json;charset=UTF-8',
        success: function (res) {
            if (res) {
                bootbox.alert("授权文件已生效！");
            } else {
                bootbox.alert("授权文件无效，请重新上传！");
            }
        }
    });
});
function getSNNumber() {
    $.ajax({
        type: "POST",
        url: postPath + '/system/authorization/getComputerSN',
        data: "",
        dataType: 'json',
        async: false,
        //contentType:'application/json;charset=UTF-8',
        success: function (res) {
            if (res.success) {
                $('#sn_number').html(res.data);

            } else {
                bootbox.alert(res.msg);
            }
        }
    });
}

